<?php

/**
*  单例模式
*/
class Demo
{
	//1.私有静态属性，保存当前类的实例
	private static $instance = null;

	//2.构造方法私有化，禁止从外部用new 来创造实例
	private function __construct(){

	}

	//3.克隆方法私有化,禁止从外部使用克隆方法来生成本类的实例
	private function __clone(){

	}

	//4.生成当前类的唯一实例
	private static function getInstance(){
		//若果不是当前类的实例，那么实例化当前类创建新实例
		if(!self::$instance instanceof self){
			self::$instance = new self();
		}

		return self::$instance;
	}

	
}



$obj1 = Demo::getInstance();
$obj2 = Demo::getInstance();
$obj3 = Demo::getInstance();
$obj4 = Demo::getInstance();
$obj5 = Demo::getInstance();
var_dump($obj1,$obj2,$obj3,$obj4,$obj5);